package com.jdrx.sw.sewage.common.util;

import com.jdrx.platform.commons.rest.exception.BizException;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Map;

/**
 * Create by dengfan at 2019/6/13 0013 19:05
 */
@UtilityClass
public class Asserts {

    public void check(final boolean expression,final String errMsg) throws BizException {
        if (!expression){
            throw new BizException(errMsg);
        }
    }

    public void check(final boolean expression, final String message, final Object... args) throws BizException {
        if (!expression) {
            throw new BizException(String.format(message, args));
        }
    }

    public void check(final boolean expression, final String message, final Object arg) throws BizException {
        if (!expression) {
            throw new BizException(String.format(message, arg));
        }
    }

    public void notNull(final Object object, final String name) throws BizException {
        if (object == null) {
            throw new BizException(name + "不能为空");
        }
    }

    public void notBlank(final CharSequence s, final String name) throws BizException {
        if (StringUtils.isBlank(s)) {
            throw new BizException(name + "不能为空");
        }
    }

    public void notEmpty(Collection<?> coll, String name) throws BizException {
        if (CollectionUtils.isEmpty(coll)) {
            throw new BizException(name + "不能为空");
        }
    }

    public void notEmpty(Map<? , ?> map, String name) throws BizException{
        if (CollectionUtils.isEmpty(map)) {
            throw new BizException(name + "不能为空");
        }
    }

}
